<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('科目明细账')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>年度：</label>
                                <input type="text" name="params[nd]" th:value="${year}" id="nd"/>
                            </li>
                            <li>
                                <label>起月份：</label>
                                <input type="text" name="params[syf]" th:value="${term}"/>
                            </li>
                            <li>
                                <label>止月份：</label>
                                <input type="text" name="params[eyf]" th:value="${term}"/>
                            </li>
							<li>
								<label>科目级别：</label>
								<select name="params[kmjb]" id="kmjb">
									<option value="1">1级</option>
									<option value="2" selected="selected" >2级</option>
									<option value="3">3级</option>
									<option value="4">4级</option>
								</select>
							</li>
                            <li >
								<label>科目代码： </label><select name="params[kmdm]" id="kmdm">
									<option th:each="kmdm : ${kmdmlist}" th:text="${kmdm.kmdm}+'-'+${kmdm.kmmc}" th:value="${kmdm.kmdm}"></option>
								</select>
							</li>
                            <li>
                                <label>未记账：</label>
                                <input type="checkbox" name="params[sfjz]" />
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:infoaccount:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table">
                  <table>
		  			<tr><td>核算期间:</td></tr>
		  			<tr><td>凭证范围:</td></tr>
		  		  </table>
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript"> 
        var prefix = ctx + "system/infoaccount";
        $(function() {
            var options = {
                url: prefix + "/list", 
                exportUrl: prefix + "/export",
                modalName: "科目明细账",
                showFooter: true,
                columns: [{
                    checkbox: true
                },
                {
		            field: 'pztxh',
		            visible: false
		        },
                {
                    field: 'nd',
                    title: '年'
                },{
                    field: 'yf',
                    title: '月'
                },{
                    field: 'rq',
                    title: '日'
                },{
                    field: 'pzzh',
                    title: '凭证字号'
                },{
                    field: 'zy',
                    title: '摘要'
                },
                {
                    field: 'jfje',
                    title: '借方金额'
                },
                {
                    field: 'dfje',
                    title: '贷方金额'
                },{
                    field: 'jdfx',
                    title: '借贷方向',
		        	formatter: function (value, row, index) {
		        		return status(row);
		        	}
                },{
                    field: 'qcye',
                    title: '余额',
                    width:150,
                    formatter: function(value, row, index) { 
                        return formatJr(row.qcye.toString(),'30','150','');
                    }
                }]
            };
            $.table.init(options);
        });
    	/* 用户状态显示 */
		function status(row) {
		    if (row.jdfx =='1') {
    			return '借';
    		} else if (row.jdfx =='-1'){
    			return '贷';
    		}else{
    			return '';
    		}
		}
    	
		$("#kmjb").change(function(){
			$.ajax({
				url:prefix + "/kmdmlist", 
				data:{params:{nd:$("#nd").val(),kmjb:$("#kmjb").val()}},
				type:"post",
				success:function(data){
					debugger;
					$("#kmdm").empty(); 
					var areaList = data.rows;
					for(var i=0;i<areaList.length;i++){
						//这里两个方法是首先转化为json字符串，然后转化为json对象
						var json = JSON.stringify(areaList[i]);
						var area = JSON.parse(json);
						var str = "<option value="+area['kmdm']+">"+area['kmdm']+"-"+area['kmmc']+"</option>";             
						$("#kmdm").append(str);
					}

					$("#kmdm").trigger("liszt:updated");
					$("#kmdm").trigger("chosen:updated");
				}
			});
		});
    	
    </script>
</body>
</html>